package com.lb.stream;

import cn.hutool.core.date.StopWatch;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: zhangjun
 * @date: 2024/10/22
 */
public class ParallelTest {

    /**
     * 并行求和
     * @param args
     */
    public static int addIntegers(List<Integer> values) {
        return values.parallelStream().mapToInt(i -> i).sum();
    }
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(20,21,30,90,20,1,2,44,98,101,23,433,223,123);
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        int i = addIntegers(list);
        System.out.println("i=" + i);
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());


        stopWatch.start();
        int count = 0;
        for (Integer integer : list) {
            count += integer;
        }
        System.out.println("count=" + count);
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());

        List<String> list1 = new ArrayList<String>();
        System.out.println(list1.stream().map(item -> item + "文件数").collect(Collectors.joining(",")));

        String ss = "你好，世界";
        System.out.println(ss.length());
        System.out.println(ss.getBytes().length);
    }
}
